package tutorial.lite_mod.admin_power;

import com.google.common.base.Joiner;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import public_util.model.Const4PublicDataBase;
import public_util.model.PublicDataAdminUser;
import public_util.model.PublicMiddleTable;
import public_util.model.ReturnData;
import system_api_4_trade.dao.ApiPublicMiddleTableMapper;
import system_api_4_trade.util.sql.SelectTool;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 这个类用来提供给before和after方法使用
 * https://note.youdao.com/ynoteshare/index.html?id=3c88200c51f951f6e18fa590b6e3f6c8&type=note&_time=1663293584446
 * 传递特殊参数, 可以演示的模板部分
 * 后面大部分的配置, 都是前端自己传过来比较稳妥
 * 每个传参对应一个相应的方法
 */
public class TemplateUtilApi {

    private static Logger logger = Logger.getLogger(TemplateUtilApi.class);


    /**
     * 验证链接: duzikai_api_mgr_public_data_admin_user?account_user=my_admin&password_user=jlt110&pre_cmd_para_need_pic_code=false&invoke_method=public_page_4m_login_data_admin&pre_cmd_para_show_admin_tree=true
     * 工具零件方法
     * 组装方法: 主要是在before活着after方法里面调用
     * 根据这个零件来拼装
     * @return
     */
    public static ReturnData pre_cmd_para_show_admin_tree(PublicDataAdminUser adminUser, HttpServletRequest request, SqlSession session, HashMap<String, Object> params2db, ReturnData resultData)
    {
        ApiPublicMiddleTableMapper middleTableMapper = session.getMapper(ApiPublicMiddleTableMapper.class);
        String pre_cmd_para_show_admin_tree = request.getParameter("pre_cmd_para_show_admin_tree");
        if ("true".equals(pre_cmd_para_show_admin_tree))
        {
            resultData.getReturnData().put("mulu_list","");
            PublicMiddleTable jueseData = find_public_middle_table_juese(middleTableMapper, adminUser.getId_public_data_admin_user() + "");
            if (jueseData != null)
            {
                String id_tables = find_public_middle_table_mulu(middleTableMapper,jueseData.getMid_table_remark_001());
                List<PublicMiddleTable> lastData = find_public_middle_table_path(middleTableMapper, id_tables);
                resultData.getReturnData().put("mulu_list",lastData);
            }

        }
        return null;
    }


    //查角色
    public static PublicMiddleTable find_public_middle_table_juese(ApiPublicMiddleTableMapper midMapper, String id_admin)
    {
        HashMap<String, Object> paraPrice = new HashMap<String, Object>();
        paraPrice.put(Const4PublicDataBase.PARA_type_middle_app, 12001);
        paraPrice.put(Const4PublicDataBase.PARA_type_inner_app, 1001);
        paraPrice.put(Const4PublicDataBase.PARA_is_online, 0);
        paraPrice.put(Const4PublicDataBase.PARA_id_public_data_admin_user+ "_in", id_admin);
        HashMap<String, Object>  realPara = SelectTool.paramap2selectMap(paraPrice, "public_middle_table_lite_mod_admin_power");
        List<PublicMiddleTable> listQianyuePrice = midMapper.tableDataList(realPara);//查询是否具备值
        if (listQianyuePrice == null || listQianyuePrice.size() == 0)
        {
            return null;
        }
        return listQianyuePrice.get(0);
    }

    //查目录
    public static String find_public_middle_table_mulu(ApiPublicMiddleTableMapper midMapper, String juse)
    {
        HashMap<String, Object> paraPrice = new HashMap<String, Object>();
        paraPrice.put(Const4PublicDataBase.PARA_type_middle_app, 11001);
        paraPrice.put(Const4PublicDataBase.PARA_type_inner_app, 1001);
        paraPrice.put(Const4PublicDataBase.PARA_is_online, 0);
        paraPrice.put(Const4PublicDataBase.PARA_id_public_middle_table+ "_in", juse);
        HashMap<String, Object>  realPara = SelectTool.paramap2selectMap(paraPrice, "public_middle_table_lite_mod_admin_power");
        List<PublicMiddleTable> listQianyuePrice = midMapper.tableDataList(realPara);//查询是否具备值
        if (listQianyuePrice == null || listQianyuePrice.size() == 0)
        {
            return null;
        }
        //返回逗号隔开的ID
        PublicMiddleTable reData = listQianyuePrice.get(0);

        return reData.getMid_table_remark_003();
    }


    //查路径
    public static List<PublicMiddleTable> find_public_middle_table_path(ApiPublicMiddleTableMapper midMapper, String mulu)
    {
        HashMap<String, Object> paraPrice = new HashMap<String, Object>();
        paraPrice.put(Const4PublicDataBase.PARA_type_middle_app, 13001);
        paraPrice.put(Const4PublicDataBase.PARA_type_inner_app, 1001);
        paraPrice.put(Const4PublicDataBase.PARA_is_online, 0);
        paraPrice.put(Const4PublicDataBase.PARA_id_public_middle_table+ "_in", mulu);
        HashMap<String, Object>  realPara = SelectTool.paramap2selectMap(paraPrice, "public_middle_table_lite_mod_admin_power");
        List<PublicMiddleTable> listQianyuePrice = midMapper.tableDataList(realPara);//查询是否具备值
        return listQianyuePrice;
    }




}
